package elementos;

import java.awt.Graphics;
import java.util.ArrayList;

public class Composite implements Drawable{
    private ArrayList<Drawable> objects;
    
    public int size(){
        return objects.size();
    }
    
    public Composite(){
        objects=new ArrayList<Drawable>();
    }

    @Override
    public void render(Graphics g) {
        for(int i=0;i<objects.size();i++){
            objects.get(i).render(g);
        }
    }

    @Override
    public void add(Drawable d) {
        objects.add(d);
    }

    @Override
    public void remove(Drawable d) {
        objects.remove(d);
    }

    @Override
    public Drawable getChild(int i) {
        return objects.get(i);
    }

    @Override
    public Drawable collision(Drawable d) {
        for(int i=0;i<objects.size();i++){
            if (!objects.get(i).equals(d)){
                if(objects.get(i).collision(d)!=null){
                    return objects.get(i);
                }
            }
        }
        return null;
    }
    
}
